package com.green.voluntaryfiling.util;

import java.text.DecimalFormat;

public class HistorySchoolAcceptanceRateUtil {

    /**
     *【录取指数：S分考A学校，A校往年分数是a。那么往年最低分是[a,满分]
     * 的所有学校今年招生人数总和为c，s最低排位（数最大）是x，
     * 则s分考上A的录取指数是c/x。本质是s分考上往年a分的学校的录取指数是c/x】
     *
     * 录取取数 0.6-2 在算概率
     * @param lowest_ranking_st_score  学生分数最低排位  s
     *  score 学校录取最低分数    a分
     * @param st_score 学生分数    s分
     * @param allExceedSchoolScoreAccpectedPerson 学校招生人数  录取分数为[a,满分]的学校招生总人数 c
     *        s分考上A的录取指数是c/x
     * @return
     */
    public static Double percent(Double lowest_ranking_st_score, Double st_score,int allExceedSchoolScoreAccpectedPerson){
        DecimalFormat df = new DecimalFormat("#0.00");
        double forecastIndices = allExceedSchoolScoreAccpectedPerson / lowest_ranking_st_score;//预测指数
        double total_percent = 1;
        if (st_score > 550) {
            return percentTop(total_percent, forecastIndices);
        } else if (st_score >= 450 && st_score <= 550) {
            return percentMiddle(total_percent, forecastIndices);
        } else {
            return percentBottom(total_percent, forecastIndices);
        }


    }

    //头部区段的预测录取概率（550以上）
    public static Double percentTop(double total_percent, double forecastIndices) {
        DecimalFormat df = new DecimalFormat("#0.00");

        if (forecastIndices >= 1.5) {
            total_percent = 0.95;
            //当大于1.5时，概率则按一定公式扣除概率（0.95以上）
            total_percent += (50 - forecastIndices) / 48.5 * 0.05;

            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 1.2) {
            total_percent = 0.95;
            //当大于1.2时，概率则按一定公式扣除概率（0.90-0.95）
            total_percent -= (1.5 - forecastIndices) * 3.3 * 0.05;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 1) {
            total_percent = 0.90;
            //当大于1时，概率则按一定公式扣除概率（0.80-0.90）
            total_percent -= (1.2 - forecastIndices) * 5 * 0.10;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 0.9) {
            total_percent = 0.80;
            //当大于0.9时，概率则按一定公式扣除概率（0.65-0.80）
            total_percent -= (1 - forecastIndices) * 1.5;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 0.7) {
            total_percent = 0.65;
            //当大于0.7时，概率则按一定公式扣除概率（0.45 -0.65）
            total_percent -= (0.9 - forecastIndices) * 5 * 0.2;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.5) {
            total_percent = 0.45;
            //当大于0.5时，概率则按一定公式扣除概率（0.25 -0.45）
            total_percent -= (0.7 - forecastIndices) * 5 * 0.2;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.3) {
            total_percent = 0.25;
            //当大于0.3时，概率则按一定公式扣除概率（0.05 -0.25）
            total_percent -= (0.5 - forecastIndices) * 5 * 0.20;
            return Double.valueOf(df.format(total_percent * 100));
        } else {
            //当小于0.3时，概率则按一定公式扣除概率（0.00 -0.05）
            total_percent = 0.05;
            total_percent -= (0.3 - forecastIndices) * 3.33 * 0.05;
            return Double.valueOf(df.format(total_percent * 100));

        }
    }

    //中间区段的预测录取概率（450-550）
    public static Double percentMiddle(double total_percent, double forecastIndices) {
        DecimalFormat df = new DecimalFormat("#0.00");

        if (forecastIndices >= 2) {
            //当大于2时，概率则按一定公式扣除概率（0.95为基础），按比例增加
            total_percent = 0.95;

            total_percent += (50 - forecastIndices) / 48 * 0.05;

            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 1.8) {
            //当大于1.8时，概率则按一定公式扣除概率（0.95-1）
            total_percent -= (2 - forecastIndices) * 5 * 0.005;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 1.5) {
            total_percent = 0.9;
            //当大于1.5时，概率则按一定公式扣除概率（0.85 -0.9）
            total_percent -= (1.8 - forecastIndices) * 3.3 * 0.05;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 1.2) {
            total_percent = 0.85;
            //当大于1.2时，概率则按一定公式扣除概率（0.75-0.85）
            total_percent -= (1.5 - forecastIndices) * 3.3 * 0.10;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 1) {
            total_percent = 0.75;
            //当大于1时，概率则按一定公式扣除概率（0.65-0.75）
            total_percent -= (1.2 - forecastIndices) * 5 * 0.05;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 0.9) {
            total_percent = 0.70;
            //当大于0.9时，概率则按一定公式扣除概率（0.45 -0.70）
            total_percent -= (1 - forecastIndices) * 2.5;
            return Double.valueOf(df.format(total_percent * 100));

        } else if (forecastIndices >= 0.7) {
            total_percent = 0.45;
            //当大于0.7时，概率则按一定公式扣除概率（0.35 -0.45）
            total_percent -= (0.9 - forecastIndices) * 5 * 0.1;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.5) {
            total_percent = 0.35;
            //当大于0.5时，概率则按一定公式扣除概率（0.15 -0.35）
            total_percent -= (0.7 - forecastIndices) * 5 * 0.2;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.3) {
            total_percent = 0.15;
            //当大于0.3时，概率则按一定公式扣除概率（0.05 -0.15）
            total_percent -= (0.5 - forecastIndices) * 5 * 0.10;
            return Double.valueOf(df.format(total_percent * 100));
        } else {
            //当小于0.3时，概率则按一定公式扣除概率（0.00 -0.05）
            total_percent = 0.05;
            total_percent -= (0.3 - forecastIndices) * 3.33 * 0.05;
            return Double.valueOf(df.format(total_percent * 100));

        }
    }

    //底部区段的预测录取概率（450以下）
    public static Double percentBottom(double total_percent, double forecastIndices) {
        DecimalFormat df = new DecimalFormat("#0.00");

        if (forecastIndices >= 0.7) {
            total_percent = 0.90;
            //当大于0.7时，概率则按一定公式扣除概率（0.90 - 1）
            total_percent += (50 - forecastIndices) / 49.3 * 0.10;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.6) {
            //当大于0.7时，概率则按一定公式扣除概率（0.65 - 0.9）
            total_percent = 0.90;
            total_percent -= (0.7 - forecastIndices) * 2.5;
            return Double.valueOf(df.format(total_percent * 100));
        } else if (forecastIndices >= 0.5) {
            total_percent = 0.40;
            //当大于0.5时，概率则按一定公式扣除概率（0.40 -0.65）
            total_percent -= (0.7 - forecastIndices) * 5 * 0.25;
            return Double.valueOf(df.format(total_percent * 100));
        } else if(forecastIndices>=0.4){
            total_percent = 0.55;
            //当大于0.3时，概率则按一定公式扣除概率（0.35 -0.55）
            total_percent -= (0.5 - forecastIndices) * 5 * 0.20;
            return Double.valueOf(df.format(total_percent * 100));
        }
        else if (forecastIndices >= 0.3) {
            total_percent = 0.35;
            //当大于0.3时，概率则按一定公式扣除概率（0.25 -0.35）
            total_percent -= (0.5 - forecastIndices) * 5 * 0.10;
            return Double.valueOf(df.format(total_percent * 100));
        }else {
            //当小于0.3时，概率则按一定公式扣除概率（0.00 -0.05）
            total_percent = 0.25;
            total_percent -= (0.3 - forecastIndices) * 3.33 * 0.25;
            return Double.valueOf(df.format(total_percent * 100));

        }
    }

}
